import unittest

import requests
import app
from api.login import LoginApi
import json

from parameterized import parameterized
import utils


class TestImgVerifyCode(unittest.TestCase):

    @classmethod
    def setUpClass(cls) -> None:
        cls.login_api = LoginApi()

    def setUp(self) -> None:
        self.session = requests.Session()

    def tearDown(self) -> None:
        self.session.close()

    # 获取图片验证码
    # @parameterized.expand(utils.build_data("img_verify_code.json"))
    @parameterized.expand(utils.build_data_new("img_verify_code.json", "num,status_code"))
    def test_get_img_verify_code(self, num, status_code):
        print(f" num={num} status_code={status_code}")
        # 测试数据
        # r = 0.123123123123

        # 调用接口
        response = self.login_api.get_img_verify_code(self.session, num)

        # 断言
        self.assertEqual(status_code, response.status_code)

    # # 获取图片验证码成功(r为随机小数)
    # def test01_get_img_verify_code_for_float(self):
    #     # 测试数据
    #     r = 0.123123123123
    #
    #     # 调用接口
    #     response = self.login_api.get_img_verify_code(self.session, r)
    #
    #     # 断言
    #     self.assertEqual(200, response.status_code)
    #
    # # 获取图片验证码成功(r为随机整数)
    # def test02_get_img_verify_code_for_int(self):
    #     # 测试数据
    #     r = 3123123123
    #
    #     # 调用接口
    #     response = self.login_api.get_img_verify_code(self.session, r)
    #
    #     # 断言
    #     self.assertEqual(200, response.status_code)
    #
    # # 获取图片验证码失败(r为空)
    # def test03_get_img_verify_code_for_empty(self):
    #     # 测试数据
    #     r = ""
    #
    #     # 调用接口
    #     response = self.login_api.get_img_verify_code(self.session, r)
    #
    #     # 断言
    #     self.assertEqual(404, response.status_code)
